home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH06 / PGM6_1.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-10  |  1.9 KB  |  109 lines

  1. ; Simple Arithmetic
  2. ; This program demonstrates some simple arithmetic instructions.
  3.  
  4.         .386            ;So we can use extended registers
  5.         option    segment:use16    ; and addressing modes.
  6.  
  7. dseg        segment    para public 'data'
  8.  
  9. ; Some type definitions for the variables we will declare:
  10.  
  11. uint        typedef    word        ;Unsigned integers.
  12. integer        typedef    sword        ;Signed integers.
  13.  
  14.  
  15. ; Some variables we can use:
  16.  
  17. j        integer    ?
  18. k        integer    ?
  19. l        integer    ?
  20.  
  21. u1          uint    ?
  22. u2        uint    ?
  23. u3        uint    ?
  24.  
  25. dseg        ends
  26.  
  27. cseg        segment    para public 'code'
  28.         assume    cs:cseg, ds:dseg
  29.  
  30. Main        proc
  31.         mov    ax, dseg
  32.         mov    ds, ax
  33.         mov    es, ax
  34.  
  35. ; Initialize our variables:
  36.  
  37.         mov    j, 3
  38.         mov    k, -2
  39.  
  40.         mov    u1, 254
  41.         mov    u2, 22
  42.  
  43. ; Compute L := j+k and u3 := u1+u2
  44.  
  45.         mov    ax, J
  46.         add    ax, K
  47.         mov    L, ax
  48.  
  49.         mov    ax, u1        ;Note that we use the "ADD"
  50.         add    ax, u2        ; instruction for both signed
  51.         mov    u3, ax        ; and unsigned arithmetic.
  52.  
  53. ; Compute L := j-k and u3 := u1-u2
  54.  
  55.         mov    ax, J
  56.         sub    ax, K
  57.         mov    L, ax
  58.  
  59.         mov    ax, u1        ;Note that we use the "SUB"
  60.         sub    ax, u2        ; instruction for both signed
  61.         mov    u3, ax        ; and unsigned arithmetic.
  62.  
  63. ; Compute L := -L
  64.  
  65.         neg    L
  66.  
  67. ; Compute L := -J
  68.  
  69.         mov    ax, J        ;Of course, you would only use the
  70.         neg    ax        ; NEG instruction on signed values.
  71.         mov    L, ax
  72.  
  73. ; Compute K := K + 1 using the INC instruction.
  74.  
  75.         inc    K
  76.  
  77. ; Compute u2 := u2 + 1 using the INC instruction.
  78. ; Note that you can use INC for signed and unsigned values.
  79.  
  80.         inc    u2
  81.  
  82. ; Compute J := J - 1 using the DEC instruction.
  83.  
  84.         dec    J
  85.  
  86. ; Compute u2 := u2 - 1 using the DEC instruction.
  87. ; Note that you can use DEC for signed and unsigned values.
  88.  
  89.         dec    u2
  90.  
  91.  
  92.  
  93.  
  94.  
  95. Quit:        mov    ah, 4ch            ;DOS opcode to quit program.
  96.         int    21h            ;Call DOS.
  97. Main        endp
  98.  
  99. cseg        ends
  100.  
  101. sseg        segment    para stack 'stack'
  102. stk        byte    1024 dup ("stack   ")
  103. sseg        ends
  104.  
  105. zzzzzzseg    segment    para public 'zzzzzz'
  106. LastBytes    byte    16 dup (?)
  107. zzzzzzseg    ends
  108.         end    Main
  109.